package com.example.startapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.startapp.R;
import com.example.startapp.entity.Purchase;

import java.util.List;

public class SalesAdapter extends ArrayAdapter<Purchase> {
    public SalesAdapter(Context context, List<Purchase> purchases){
        super(context, R.layout.sales_test,purchases);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.sales_test, parent, false);
        }

        Purchase purchase = getItem(position);
        TextView purChaseShopId =convertView.findViewById(R.id.sale_t1);
        TextView purChaseShopName =convertView.findViewById(R.id.sale_t2);
        TextView purChaseComName=convertView.findViewById(R.id.sale_t3);
        TextView purChaseQuantity= convertView.findViewById(R.id.sale_t4);

//
        purChaseShopId.setText(purchase.getShop() == null ||  purchase.getShop().getShopId()==null ? " " :purchase.getShop().getShopId().toString());
        purChaseShopName.setText(purchase.getShop() == null ||  purchase.getShop().getShopName()==null ? " " :purchase.getShop().getShopName());
        purChaseComName.setText(purchase.getCommodity() == null ||  purchase.getCommodity().getCommodityName()==null ? " " :purchase.getCommodity().getCommodityName());
        purChaseQuantity.setText(purchase.getQuantity() == null ? " " : purchase.getQuantity().toString());


        return convertView;
    }
}
